import type  { ObjectType, RegistrableApp } from 'qiankun'
import type {Callback} from './type'

export function getAppsConfig() {
  return [
    {
      name: 'vueApp',
      entry: '//localhost:3001',
      container: '#app1',
      activeRule: (location: Location) => {
        return location.pathname.startsWith('/app1')
      },
      props: {}
    }
  ]
}

export function getMicroApps(callback?: Callback) {
  const appsConfig = getAppsConfig()

  const microApps: RegistrableApp<ObjectType>[] = appsConfig.map(config => {
    const {name, entry, container} = config
    let data= {
      name,
      entry,
      container: container || `#${name}`,
      activeRule: (location: Location) => {
        if(location.hash) {
          return false
        } else {
          let regExp = new RegExp(`/base/${name}`)
          return regExp.test(location.pathname)
        }
      },
      sandbox: {
        stictStyleIsolation: true
      },
      props: {
        testName: 'mal'
      }
    }

    let value = callback?.(data)

    return value || data
  })

  return microApps
}